//
//  BDMPGCheckBoxButton.m
//  pangu
//
//  Created by zhengyueming on 15/9/25.
//  Copyright (c) 2015年 baidu.com. All rights reserved.
//

#import "BDMPGCheckBoxButton.h"

#define PG_RADIO_ICON_WH                     (16.0)
#define PG_ICON_TITLE_MARGIN                 (5.0)

@implementation BDMPGCheckBoxButton

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {

        self.exclusiveTouch = YES;

        self.frame = frame;
        [self setTitleColor:kBDMBaseTextColor forState:UIControlStateNormal];
        UIImage *image1 = [UIImage imageNamed:@"cb_glossy_off"];
        UIImage *image2 = [UIImage imageNamed:@"cb_glossy_on"];
        
        [self setImage:image1 forState:UIControlStateNormal];
        [self setImage:image2 forState:UIControlStateSelected];
        [self setImage:image2 forState:UIControlStateHighlighted];
        self.imageEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
        [self addTarget:self action:@selector(checkBoxBtnChecked) forControlEvents:UIControlEventTouchUpInside];
    }
    return self;
}


- (void)checkBoxBtnChecked {
    self.selected = !self.selected;
}

- (CGRect)imageRectForContentRect:(CGRect)contentRect {
    return CGRectMake(0, (CGRectGetHeight(contentRect) - PG_RADIO_ICON_WH)/2.0, PG_RADIO_ICON_WH, PG_RADIO_ICON_WH);
}

- (CGRect)titleRectForContentRect:(CGRect)contentRect {
    return CGRectMake(PG_RADIO_ICON_WH + PG_ICON_TITLE_MARGIN, 0,
                      CGRectGetWidth(contentRect) - PG_RADIO_ICON_WH - PG_ICON_TITLE_MARGIN,
                      CGRectGetHeight(contentRect));
}

@end
